Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add alignment definitions to RTCHitNt and RTCRayNt #472

Closed
wants to merge 1 commit into from

Conversation

dbs4261
Copy link
Contributor

@dbs4261 dbs4261 commented Jan 19, 2024

Alignment definitions should be added to RTCHitNt and RTCRayNt templates so they match the C definitions provided. The following static assertions demonstrate the issues with using the RTCRayNt templates as they all fail because RTCRayNt has an alignment of 4, equivalent to alignof(float).

static_assert(alignof(embree::RTCRayNt<1>) == alignof(embree::RTCRay));
static_assert(alignof(embree::RTCRayNt<4>) == alignof(embree::RTCRay4));
static_assert(alignof(embree::RTCRayNt<8>) == alignof(embree::RTCRay8));
static_assert(alignof(embree::RTCRayNt<16>) == alignof(embree::RTCRay16));

As the alignment calculation in the PR is nasty as it avoids requiring the alignof keyword, or constexpr functions, this could instead be hidden behind a macro. Maybe RTC_ALIGN_SOA_AT_LEAST(N, MIN)?

The code is equivalent to:

constexpr std::size_t AlignSOAAtLeast(unsigned N, std::size_t min_alignment) noexcept {
    if (std::has_single_bit<unsigned>(N)) {
        return std::max<std::size_t>(min_alignment, N * alignof(float));
    } else {
        return min_alignment;
    }
}

Added alignment definitions to RTCHitNt and RTCRayNt templates so they match the C definitions provided. As the alignment calculation is nasty without requiring the alignof keyword, or constexpr functions, this could instead be hidden behind a macro. Maybe RTC_ALIGN_SOA_AT_LEAST(N, MIN)?

The code is equivalent to:
```
constexpr std::size_t AlignSOAAtLeast(unsigned N, std::size_t min_alignment) noexcept {
    if (std::has_single_bit<unsigned>(N)) {
        return std::max<std::size_t>(min_alignment, N * alignof(float));
    } else {
        return min_alignment;
    }
}
```
Checking this works is as simple as adding a few static assertions:
```
static_assert(alignof(embree::RTCRayNt<1>) == alignof(embree::RTCRay));
static_assert(alignof(embree::RTCRayNt<4>) == alignof(embree::RTCRay4));
static_assert(alignof(embree::RTCRayNt<8>) == alignof(embree::RTCRay8));
static_assert(alignof(embree::RTCRayNt<16>) == alignof(embree::RTCRay16));
```
@freibold
Copy link
Contributor

Thanks for the PR! I've merged this into the devel branch manually 819aedb

@freibold freibold closed this May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants